package com.itheima.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.controller.Code;
import com.itheima.dao.BookDao;
import com.itheima.domain.Book;
import com.itheima.exception.BusinessException;
import com.itheima.exception.SystemException;
import com.itheima.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BookServiceImpl extends ServiceImpl<BookDao,Book> implements BookService {
    //由于idea不能很好的识别spring整合myabtis的配置,所以可能报错,但实际运行没有问题
 /*   @Autowired
    private BookDao bookDao;

    //TODO:
    public Book getById(Integer id) {
        if(id < 0){
            //业务异常: 用户造成的
            throw new BusinessException(Code.BUSINESS_ERR,"id不能小于0");
        }
        Book book = null;
        try {
            //数据库可能有问题,抛出异常
            book = bookDao.selectById(id);
        } catch (Exception e) {
            throw new SystemException(Code.SYSTEM_ERR,"当前访问人数较多,请稍后访问");
        }
        //模拟未知异常
        return book;
    }*/

}
